package com.ggmc;

/// google contact access

import com.google.gdata.client.contacts.ContactsService;
import com.google.gdata.data.contacts.ContactFeed;
import com.google.gdata.util.AuthenticationException;
import com.google.gdata.util.ServiceException;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

	public class Contacts {
      
	 public ContactFeed FetchContacts(String user, String pass) {
      try {
        
        System.out.println("Accessing Google Contacts...\n");
        // Create a new Contacts service
        ContactsService myService = new ContactsService("My Application");
        myService.setUserCredentials(user,pass);
        System.out.println(user);
        System.out.println(pass);
        // Get a list of all entries
        URL metafeedUrl = new URL("http://www.google.com/m8/feeds/contacts/"+user+"/base");
        System.out.println("Getting Contacts entries...\n");
        ContactFeed resultFeed = myService.getFeed(metafeedUrl, ContactFeed.class);
          return resultFeed;
      }
      catch(AuthenticationException e) {
        e.printStackTrace();
      }
      catch(MalformedURLException e) {
        e.printStackTrace();
      }
      catch(ServiceException e) {
        e.printStackTrace();
      }
      catch(IOException e) {
        e.printStackTrace();
      }
	return null;
    }
  }